/**
 * 
 */
package ch.ifage.business.dom;

import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author Christian
 *
 */
public class StepTest {
	
	
	/**
	 * step à tester.
	 */
	private Step s;
	
	/**
	 * le père du step à tester.
	 */
	private Step father = new Step();
	
	/**
	 * fils 1.
	 */
	private Step son1 = new Step();

	/**
	 * fils 2.
	 */
	private Step son2 = new Step();
	
	/**
	 * identité du step.
	 */
	private StepIdentity si = new StepIdentity(1, "serverY", "instanceZ");
	
	/**
	 * propriété du step.
	 */
	private StepProperties sp = new StepProperties("fichier.xml", new GregorianCalendar(), new GregorianCalendar(), 
			 Activity.ARCHIVE, "parameter", Status.SUCCESS, "log");
	
	/**
	 * before.
	 */
	@Before
	public void init() {		
		s = new Step(si, sp, father);
		son1.setProperties(new StepProperties("fichier1.xml", new GregorianCalendar(), new GregorianCalendar(), 
				 Activity.ARCHIVE, "parameter", Status.SUCCESS, "text1"));
		s.addChildStep(son1);
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#getFather()}.
	 */
	@Test
	public final void testGetFather() {
		Assert.assertTrue(s.getFather().equals(father));
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#setFather(ch.ifage.business.dom.Step)}.
	 */
	@Test
	public final void testSetFather() {
		Step newFather = new Step();
		s.setFather(newFather);
		Assert.assertTrue(s.getFather().equals(newFather));
	}	
	
	/**
	 * Test method for {@link ch.ifage.business.dom.Step#getProperties()}.
	 */
	@Test
	public final void testGetProperties() {
		Assert.assertTrue(s.getProperties().equals(sp));
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#setProperties(ch.ifage.business.dom.StepProperties)}.
	 */
	@Test
	public final void testSetProperties() {
		/**
		 * propriété du step 2.
		 */
		StepProperties spNew = new StepProperties("fichier2.xml", new GregorianCalendar(), new GregorianCalendar(), 
				 Activity.ARCHIVE, "parameter", Status.SUCCESS, "log");
		s.setProperties(spNew);
		Assert.assertTrue(s.getProperties().equals(spNew));
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#getIdentity()}.
	 */
	@Test
	public final void testGetIdentitity() {
		Assert.assertTrue(s.getIdentity().equals(si));
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#setIdentity(ch.ifage.business.dom.StepIdentity)}.
	 */
	@Test
	public final void testSetIdentity() {
		/**
		 * identité du step.
		 */
		StepIdentity siNew = new StepIdentity(2, "serverY2", "instanceZ2");
		s.setIdentity(siNew);
		Assert.assertTrue(s.getIdentity().equals(siNew));
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#getListOfChild()}.
	 */
	@Test
	public final void testGetListOfChild() {
		s.addChildStep(son2);
		Assert.assertTrue(s.getListOfChild().size() == 2);
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#setListOfChild(java.util.List)}.
	 */
	@Test
	public final void testSetListOfChild() {
		List<Step> listChild = Arrays.asList(son1, son2);
		s.setListOfChild(listChild);
		Assert.assertTrue(s.getListOfChild().size() == 2);
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#Step()}.
	 */
	@Test
	public final void testStep() {
		Step s2 = new Step(si, sp, father);
		Assert.assertTrue(s2 != null); // pas très bon comme test...
	}

	/**
	 * Test method for {@link ch.ifage.business.dom.Step#addChildStep(ch.ifage.business.dom.Step)}.
	 */
	@Test
	public final void testAddChildStep() {
		s.addChildStep(son2);
		Assert.assertTrue(s.getListOfChild().size() == 2);
	}
	
	/**
	 * Test method for {@link ch.ifage.business.dom.Step#logContainsSubString(string)}.
	 */
	@Test
	public final void testlogContainsSubString() {
		Assert.assertTrue(s.logContainsSubString("log"));
		s.addChildStep(son2);
		son2.setProperties(new StepProperties("fichier2.xml", new GregorianCalendar(), new GregorianCalendar(), 
				 Activity.ARCHIVE, "parameter", Status.SUCCESS, "log2"));
		Assert.assertTrue(s.logContainsSubString("log2"));
		Assert.assertFalse(s.logContainsSubString("log3"));
	}


	/**
	 * Test method for {@link ch.ifage.business.dom.Step#toString()}.
	 */
	@Test
	public final void testToString() {
		System.out.println("Test Step:");
		System.out.println(s.toString());
		System.out.println("------------------------");
	}

}
